# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=docbook-xsl
pkgver=1.79.2
pkgrel=11
pkgdesc="XML stylesheets for Docbook-xml transformations"
url="https://docbook.org/"
arch="noarch"
license="LicenseRef-DMIT"
depends="
	docbook-xml
	libxml2-utils
	libxslt
	"
options="!check"
install="
	$pkgname-ns.post-install
	$pkgname-ns.post-upgrade
	$pkgname-ns.pre-deinstall
	$pkgname-nons.post-install
	$pkgname-nons.post-upgrade
	$pkgname-nons.pre-deinstall
	"
subpackages="
	$pkgname-ns
	$pkgname-nons
	"
source="https://github.com/docbook/xslt10-stylesheets/releases/download/release%2F$pkgver/docbook-xsl-$pkgver.tar.gz
	https://github.com/docbook/xslt10-stylesheets/releases/download/release%2F$pkgver/docbook-xsl-nons-$pkgver.tar.gz
	765567_non-recursive_string_subst.patch
	f6c5eefbca775e312afebf576a6990344a0b1b69.patch.txt
	"

prepare() {
	default_prepare
	# Only for -ns variant.
	patch -p1 < ../f6c5eefbca775e312afebf576a6990344a0b1b69.patch.txt

	builddir="$srcdir/$pkgname-nons-$pkgver" default_prepare
}

package() {
	depends="$pkgname-ns=$pkgver-r$pkgrel $pkgname-nons=$pkgver-r$pkgrel"

	mkdir -p "$pkgdir"
	install -D -m644 COPYING "$pkgdir"/usr/share/licenses/$pkgname/COPYING
}

ns() {
	pkgdesc="$pkgdesc (namespace version)"
	replaces="$pkgname"  # for backward compatibility (Alpine <3.21)

	cd "$srcdir"/$pkgname-$pkgver
	_install
}

nons() {
	pkgdesc="$pkgdesc (no-namespace version)"

	cd "$srcdir"/$pkgname-nons-$pkgver
	_install "-nons"
}

_install() {
	local suffix="${1-}"
	local dest="$subpkgdir/usr/share/xml/docbook/xsl-stylesheets-$pkgver$suffix"

	install -D -m644 VERSION VERSION.xsl -t "$dest"/
	ln -s "xsl-stylesheets-$pkgver$suffix" "${dest%/*}/xsl-stylesheets$suffix"

	local dir; for dir in \
		assembly \
		common \
		eclipse \
		epub \
		epub3 \
		fo \
		highlighting \
		html \
		htmlhelp \
		javahelp \
		lib \
		manpages \
		params \
		profiling \
		roundtrip \
		template \
		website \
		xhtml \
		xhtml-1_1 \
		xhtml5;
	do
		install -dm755 "$dest/$dir"
		local f; for f in $dir/*.xml $dir/*.xsl $dir/*.dtd $dir/*.ent; do
			[ -e "$f" ] || continue
			install -m644 $f "$dest"/$dir
		done
	done

	install -d -m755 "$subpkgdir"/etc/xml
}

sha512sums="
cd375e7a2339bcd9d24936b370c4371b351cab7c8a79044e785d0300dab75bed5a5c9b9076d4fba32d39b22535edfc6f449a7b1086139ad8bf54eab844b9434e  docbook-xsl-1.79.2.tar.gz
8764c4176abd9662f9005e7d76b1cfcceb18882404c11256a8c19bf3b44cbe4e5ff9c73b1902c4d6611708cc9ae483fe21e6185a19a3b9aeb2abcb9c19e73862  docbook-xsl-nons-1.79.2.tar.gz
3199de6b5a61ed25defa50a55fa3d138b60e1f5e4c2e3b9a14e169099189794adc3ac079fa3f62debc682f4840c6dadff40f8bd5a07fdba34fe1016ce885b9e2  765567_non-recursive_string_subst.patch
ba7b6fef55673c4d6efd6f956cc82172f44476a87b5dc0a82348ab4f1b55e043503843f31c21ca74254724d77d28696c427bc64e59e8aafebb7961420ad5fd9f  f6c5eefbca775e312afebf576a6990344a0b1b69.patch.txt
"
